package com.example.controller;

import com.example.pojo.Result;
import com.example.pojo.changeModelPojo;
import com.example.pojo.operateGuideBookPojo;
import com.example.service.operateGuideBookService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * ClassName:operateGuideBookController
 * Description:
 *
 * @Author 赵永峰
 * @Create 2024/7/19 23:16
 * @Version 1.0
 */
@Slf4j
@RestController
public class operateGuideBookController {
    @Autowired
    private operateGuideBookService operateGuideBookService;
    //插入一行全新的数据
    @PostMapping("/interOperateGuideBook")
    public Result interOperateGuideBook(@RequestBody operateGuideBookPojo operateGuideBook){
        operateGuideBookService.interOperateGuideBook(operateGuideBook);
        return Result.success();
    }
    //编辑一行数据，是表头数据
    @PostMapping("/editOperateGuideBookTable")
    public Result editOperateGuideBookTable(@RequestBody operateGuideBookPojo operateGuideBook){
        operateGuideBookService.editOperateGuideBookTable(operateGuideBook);
        return Result.success();
    }
    //删除一行数据，删除的事表头数据,修改的是int形式的数据
    @PostMapping("/editOperateGuideBookFieldInt")
    public Result editOperateGuideBookFieldInt(@RequestBody Map<String, Object> parameters){
        operateGuideBookService.editFieldInt(parameters);
        return Result.success();
    }
    //将符合条件的所有数据查出来，是按照作业指导书的类别查询的。
    @PostMapping("/inquiryOperateGuideBook")
    public Result inquiryOperateGuideBook(@RequestBody Map<String,Object> map){
        List<operateGuideBookPojo> operateGuideBookPojoList=operateGuideBookService.inquiryByOneField(map);
        return Result.success(operateGuideBookPojoList);
    }
    //编辑作业指导书的内容,修改文本类型
    @PostMapping("/editOperateGuideBookField")
    public Result editOperateGuideBookField(@RequestBody Map<String,Object> parameters){
        String filed=operateGuideBookService.editOperateField(parameters);
        return Result.success(filed);
    }
    //上传文件附件的函数
    @PostMapping("/addPictureOperateGuideBook")
    public Result addPictureOperateGuideBook(@RequestParam("file") MultipartFile file, @RequestParam Integer id, @RequestParam String fieldName, @RequestParam String fieldVal,@RequestParam String fileName){
        //上传照片的接口
        String allName = operateGuideBookService.addPictureOperateGuideBook(file,id,fieldName,fieldVal,fileName);
        return Result.success(fieldVal);
    }
    //删除图片的函数
    @PostMapping("/operateGuideBookPictureRemove")
    public Result operateGuideBookPictureRemove(@RequestBody Map<String, Object> parameters) {
        String fileName=operateGuideBookService.operateGuideBookPictureRemove(parameters);
        return Result.success(fileName);
    }
    //下载文件
    @GetMapping("/operateGuideBookDownload")
    public Result operateGuideBookDownload(@RequestParam("fileName") String fileName){
        byte[] file= operateGuideBookService.readFile(fileName);
        return Result.success(file);
    }
    //根据一个id，编辑一个字段，不需要写整行的编辑时间
    @PostMapping("/operateGuideBookOneFiledById")
    public Result operateGuideBookOneFiledById(@RequestBody Map<String,Object> map){
        operateGuideBookService.editOneFiledById(map);
        return Result.success("保存成功");
    }
}
